<template>
	<view>
		<u--textarea v-model="content" placeholder="请输入您的宝贵建议,我们会在第一时间进行查看以及改进" :border='true' ></u--textarea>
		<view style='padding:10px'>
			<u-button type='success' size='large' text='提交' @click='submit' ></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				content: '',
				phone: ''
			}
		},
		onShow() {
			this.request.get(`api/user`,{
				'@expands': "['entity.profile']"
			}).then((res) => {
				if(res.data.profile.__metadata.phone){
					this.phone = res.data.profile.__metadata.phone
				}
			})
		},
		methods: {
			submit(){
				if(this.content.trim() == ''){
					uni.showToast({
						title: '请填写您的建议',
						icon: 'none'
					})
					return
				}
				uni.showModal({
					title: '',
					content: '是否确定提交？',
					success: (data) => {
						if(data.confirm){
							uni.showLoading()
							this.request.post(`api/feedbacks`,{content: this.content, phone: this.phone,type: 'user-feedback'}).then((res) => {
								uni.hideLoading()
								uni.showModal({
									title: '',
									content: '感谢您的宝贵建议，我们会在第一时间进行处理',
									showCancel: false,
									success: () => {
										uni.switchTab({
											url: "/pages/mine/index"
										})
									}
								})
							})
						}
					}
				})
			}
		}
	}
</script>

<style>

</style>